package cn.boysoft.generate.model;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import cn.boysoft.core.annotation.JEECondition;

public class SearchParamModel extends Model{
	List<SearchField> searchFields;

	public List<SearchField> getSearchFields() {
		return searchFields;
	}

	public void setSearchFields(List<SearchField> searchFields) {
		this.searchFields = searchFields;
	}

	@Override
	Model fillDataToModel(Class entityClass) {
		java.lang.reflect.Field[] fields = entityClass.getDeclaredFields();
		if(fields != null){
			this.searchFields = new ArrayList<SearchField>();
			for(Field field : fields){
				JEECondition jeeCondition = field.getAnnotation(JEECondition.class);
				if(jeeCondition != null) {
					SearchField searchField = new SearchField();
					searchField.setFieldName(field.getName());
					searchField.setOp(jeeCondition.op());
					searchField.setFieldText(jeeCondition.text());
					this.searchFields.add(searchField);
				}
			}
		}
		return this;
	}
}
